package sch.jl.caigou.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import jiliang.purchase.demo.think_liebiao;
import jiliang.purchase.demo.think_lingxing;
import jiliang.purchase.demo.think_shenqing;
import sch.jl.caigou.dao.GoodsApplyDao;
import sch.jl.caigou.utils.getMax;

//货物/服务申请

public class GoodsApplyImpl extends DaoImpl<String> implements GoodsApplyDao
{
	
	private static String hb = null ;
	private static String sq_id = null;
	private static String id = null;

	//获取sq_id.id.bh
	public GoodsApplyImpl(String type)throws Exception
	{
		getMax GM = new getMax();
		this.hb = GM.getMaxBH(type);
		this.sq_id = GM.getMaxSq_Id();
		this.id = GM.getMaxID();
		
	}
	public GoodsApplyImpl()throws Exception
	{
		String type = "S";
		getMax GM = new getMax();
		this.hb = GM.getMaxBH(type);
		this.sq_id = GM.getMaxSq_Id();
		this.id = GM.getMaxID();
		
	}
	
	//向think_liebiao_liebiao插入新数据

	public void setNewApplyLieBiao(List<think_liebiao> list) {
		// TODO Auto-generated method stub
		for(int i=0;i<list.size();i++)
		{
			String sql = "insert into think_liebiao_sbjj value('"+(Integer.parseInt(id)+i)+"','"+(Integer.valueOf(sq_id))+"','"+list.get(i).getMingcheng()+"'," +
					"'"+list.get(i).getMiaoshu()+"','"+list.get(i).getDanwei()+"','"+list.get(i).getShuliang()+"','"+list.get(i).getDanjia()+"','"+list.get(i).getHejia()+"','"+list.get(i).getBeizhu()+"')";
			//System.out.println(sql);
			update(sql);
		}
		
	}
	//向think_liebiao_liebiao更新数据
	public void UpdateApplyLieBiao(List<think_liebiao> list_tlb,String bh) throws ClassNotFoundException, SQLException {
		// TODO Auto-generated method stub
		getMax GM = new getMax();
		List<String> id = new ArrayList<String>();
		id = GM.getLieBiaoID(bh);
		
		for(int i=0;i<list_tlb.size();i++)
		{
			String sql = "update think_liebiao_sbjj set mingcheng='"+list_tlb.get(i).getMingcheng()+"',miaoshu='"+list_tlb.get(i).getMiaoshu()+"',danwei='"+list_tlb.get(i).getDanwei()+"',shuliang='"+list_tlb.get(i).getShuliang()+"',danjia='"+list_tlb.get(i).getDanjia()+"',hejia='"+list_tlb.get(i).getHejia()+"',beizhu='"+list_tlb.get(i).getBeizhu()+"' where id='"+id.get(i)+"'";
			//System.out.println(sql);
			update(sql);
		}
		
	}

	//向think_lingxing_liebiao插入新数据
	public void setNewApplyLingXing(think_lingxing tlx) {
		// TODO Auto-generated method stub

		String sql = "insert into think_lingxing_sbjj(sq_id,bh,xiangmumc,lianxiren,fuzerengh,fuzerenxm,lianxidh,shiyongbm,gonghuosj," +
				"jingfeimc,jingfeidm,yusuanje,caigoufs,hejije,editsj) values('"+sq_id+"','"+hb+"','"+tlx.getXiangmumc()+"','"+tlx.getLianxiren()+"'," +
				"'"+tlx.getFuzerengh()+"','"+tlx.getFuzerenxm()+"','"+tlx.getLianxidh()+"','"+tlx.getDw_mc()+"','"+tlx.getGonghuosj()+"','"+tlx.getJingfeimc()+"','"+tlx.getJingfeidm()+"','"+tlx.getYusuanje()+"','"+tlx.getCaigoufs()+"','"+tlx.getHejije()+"','"+tlx.getEditsj()+"')";
		//System.out.println(sql);
		
		insert(sql);
		
		
	}
	
	//向think_lingxing_liebiao更新数据
	public void UpdateApplyLingXing(think_lingxing tlx,String bh) throws SQLException, ClassNotFoundException {
		// TODO Auto-generated method stub
		String sql = "update think_lingxing_sbjj set xiangmumc = '"+tlx.getXiangmumc()+"',lianxiren='"+tlx.getLianxiren()+"',fuzerengh='"+tlx.getFuzerengh()+"',fuzerenxm='"+tlx.getFuzerenxm()+"',lianxidh='"+tlx.getLianxidh()+"',shiyongbm='"+tlx.getDw_mc()+"',gonghuosj='"+tlx.getGonghuosj()+"',jingfeimc='"+tlx.getJingfeimc()+"',jingfeidm='"+tlx.getJingfeidm()+"',yusuanje='"+tlx.getYusuanje()+"',caigoufs='"+tlx.getCaigoufs()+"',hejije='"+tlx.getHejije()+"',editsj='"+tlx.getEditsj()+"' where bh='"+bh+"'";
		//System.out.println(sql);
		
		update(sql);
		
		
	}
	
	
	
	//向think_shenqing插入新数据
	public void setNewApplyShenQing(think_shenqing tsq){
		String sql = "insert into think_shenqing(sq_id,xm_id,dw_id,gonghao,xingming,last_lc,lc_id,states,sq_shijian,bh) values('"+sq_id+"','"+tsq.getXmid()+"','1','"+tsq.getGonghao()+"','"+tsq.getXingming()+"','"+tsq.getLast_lc()+"','"+tsq.getLc_id()+"','"+tsq.getStates()+"','"+tsq.getSq_shijian()+"','"+hb+"')";
		
		//System.out.println(sql);
		insert(sql);
	}
	
	
	//向think_shenqing更新数据
	public void updateStates(String bh){
		String sql = "update think_shenqing set states='1' where bh = '"+bh+"'";
		update(sql);
	}
	

}
